package imsdk

import (
	"encoding/json"
	"longmen/server/config/global"
	"longmen/server/pkg/common/helper/http"
)

//AV群不支持这个接口
type DeleteSenderRequest struct {
	GroupID       string `json:"GroupId"`        // 群ID
	SenderAccount string `json:"Sender_Account"` // 屏蔽账号
}

type DeleteSenderResponse struct {
	ActionStatus string `json:"ActionStatus"`
	ErrorInfo    string `json:"ErrorInfo"`
	ErrorCode    int    `json:"ErrorCode"`
}

// DeleteGroupMsgBySender 撤回群消息，撤回最近1000条消息内某个人发送的消息。
func (s sdk) DeleteGroupMsgBySender(req DeleteSenderRequest) bool {
	reqUrl := s.BuildRestfulUrl("/group_open_http_svc/delete_group_msg_by_sender")
	bytes, err := json.Marshal(req)
	if err != nil {
		global.Log.Error("request delete error: ", err)
		return false
	}
	result, err := http.HttpPost(reqUrl, string(bytes), connTimeoutMs, serveTimeoutMs, "application/json")
	resp := DeleteSenderResponse{}
	err = json.Unmarshal(result, &resp)
	if err != nil {
		global.Log.Error("request delete Unmarshal error: ", err)
		return false
	}
	if resp.ActionStatus == FailActionStatus {
		global.Log.Error("request delete  error: ", err, "error message : ", resp.ErrorInfo)
		return false
	}
	return true
}
